package com.p2p.auth.service;

/**
 * Created by Antinomy on 16/10/14.
 */

import java.awt.Color;

import com.octo.captcha.component.image.backgroundgenerator.FunkyBackgroundGenerator;
import com.octo.captcha.component.image.color.SingleColorGenerator;
import com.octo.captcha.component.image.fontgenerator.TwistedRandomFontGenerator;
import com.octo.captcha.component.image.textpaster.DecoratedRandomTextPaster;
import com.octo.captcha.component.image.textpaster.TextPaster;
import com.octo.captcha.component.image.textpaster.textdecorator.BaffleTextDecorator;
import com.octo.captcha.component.image.textpaster.textdecorator.TextDecorator;
import com.octo.captcha.component.image.wordtoimage.ComposedWordToImage;
import com.octo.captcha.component.word.wordgenerator.RandomWordGenerator;
import com.octo.captcha.engine.image.ListImageCaptchaEngine;
import com.octo.captcha.image.ImageCaptchaFactory;
import com.octo.captcha.image.gimpy.GimpyFactory;

/**
 * Sample Image Engine
 *
 * @author anti
 */
public class ImageCaptchaEngine extends ListImageCaptchaEngine {


    public ImageCaptchaEngine() {
        super();
    }


    protected void buildInitialFactories() {
        //create text parser
        TextPaster randomPaster = new DecoratedRandomTextPaster(
                new Integer(4),
                new Integer(4),
                new SingleColorGenerator(Color.BLACK),
                new TextDecorator[]{new BaffleTextDecorator(new Integer(0), Color.WHITE)}
        );
        //create image captcha factory
        ImageCaptchaFactory factory = new GimpyFactory(

                new RandomWordGenerator("1234567890"),

                new ComposedWordToImage(
                        new TwistedRandomFontGenerator(new Integer(20), new Integer(22)),
                        new FunkyBackgroundGenerator(new Integer(130), new Integer(44)),
                        randomPaster)
        );

        ImageCaptchaFactory characterFactory[] = {factory};
        this.addFactories(characterFactory);

    }


}
